package com.example.demo;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo.classes.Activeties;
import com.example.demo.classes.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ActivetiesController {
    @Autowired
    private ActivetiesMapper actMapper;

    public ActivetiesController()
    {}

    @GetMapping("/acts")
    public List<Activeties> acts()
    {
        return actMapper.selectList(null);
    }
    @GetMapping("/acts/{aid}")
    public List<Activeties> getOneUsers(@PathVariable Long aid) {
        LambdaQueryWrapper<Activeties> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Activeties::getAid,aid);
        return actMapper.selectList(lqw); // 返回200状态码和用户列表
    }
    @PostMapping("/acts")
    public Activeties createActiveties(@RequestBody Activeties act)
    {
        actMapper.insert(act);
        return act;
    }

    @PutMapping("/acts/{aid}")
    public Integer updateAct(@PathVariable Long aid, @RequestBody Activeties act)
    {return actMapper.updateById(act);}

    public ActivetiesMapper getActMapper() {
        return actMapper;
    }
}
